package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *菜品 Mapper
 */
@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 新增菜品
     */
    @AutoFill(OperationType.INSERT)

    void saveWithFlavor(Dish dish);

    /**
     * 分页查询菜品
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据主键id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 根据id批量删除菜品
     * @param ids
     */
    //sql语句：delete from dish where id in (1,2,3)
    void deleteBatch(List<Long> ids);

    /**
     * 根据id修改菜品
     * @param dish
     */
    //sql语句：update dish set category_id = ?, name = ?, price = ?, status = ?, description = ?, image = ?, create_time = ?, update_time = ?, create_user = ?, update_user = ?, is_deleted = ? where id = ?
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类id,条件查询菜品
     * @param dish
     * @return
     */

    List<Dish> list(Dish dish);
//    @Select("select * from dish where category_id = #{categoryId} and status = 1")
//    List<DishVO> list(Dish dish);
//    @Select("select * from dish where category_id = #{categoryId} and status = #{status}")
//    List<DishVO> list(@Param("categoryId") Integer categoryId, @Param("status") Integer status);
}
